import { ENUM_APP, Gateway, getGateway } from "@/droplet-bus/core.define";

import { app_gateway } from "@/droplet-bus/core.local";
import { AppLan } from "@/droplet-bus/schema.lan";

export const BusDefaultGateway: Gateway = getGateway(app_gateway, "droplet_bus_default");
export interface DotRpcInterface {
  /** 保持 tcp 链接活跃 */
  dot(): Promise<null>;
}

export const AppLanGateway: Gateway = getGateway(app_gateway, "droplet_bus_app_lan");
export type getLanRpcDto = { app: ENUM_APP };
export type getLanRpcRes = AppLan;
export type putLanRpcDto = { app: ENUM_APP; schema: AppLan };
export type putLanRpcRes = null;

export interface AppLanRpcInterface {
  getLan(dto: getLanRpcDto): Promise<getLanRpcRes>;
  putLan(dto: putLanRpcDto): Promise<putLanRpcRes>;
}

export const AppMessageGateway: Gateway = getGateway(app_gateway, "droplet_bus_app_message");
export type getMessageRpcDto = { uid: string };
export type getMessageRpcRes = string;
export type putMessageRpcDto = { uid: string; letter: string };
export type putMessageRpcRes = null;

export interface AppMessageRpcInterface {
  getMessage(dto: getMessageRpcDto): Promise<string>;
  putMessage(dto: putMessageRpcDto): Promise<null>;
}

export const AppFileGateway: Gateway = getGateway(app_gateway, "droplet_bus_app_file");
export type getFileRpcDto = { uid: string };
export type getFileRpcRes = { buffer: Buffer };

export interface AppFileRpcInterface {
  getFile(dto: getFileRpcDto): Promise<getFileRpcRes>;
}
